//
// Created by lenovo on 2022/3/10.
//

#ifndef ANRCATCHERDEMO_SIGNALHANDLER_H
#define ANRCATCHERDEMO_SIGNALHANDLER_H
#include <signal.h>

namespace AnrChecker {
    class SignalHandler {
    public:
        SignalHandler();
        virtual ~SignalHandler();
    protected:
        static const int TARGET_SIGNAL = SIGQUIT;
        virtual void onReceiving(int signal, const siginfo_t *info, void *uc) = 0;
        static bool registerHandlerLocked();
        static bool restoreHandlerLocked();
    private:
        /**
         * 信号处理器的入口函数
         * @param signal
         * @param info
         * @param uc
         */
        static void signalHandler(int signal, siginfo_t *info, void *uc);
        SignalHandler(const SignalHandler &) = delete;
        SignalHandler &operator= (const SignalHandler &) = delete;
    };
}
#endif //ANRCATCHERDEMO_SIGNALHANDLER_H
